<?php echo $this->render('/public/header'); ?>
<?php use yii\helpers\Url; ?>
    <div id="main" class="col-xs-12">
        <div>
            <button class="btn btn-success" onclick="add()">添加记录</button>
        </div>
        <br/>
        <form method="get">
            <div class="form-inline">
                <div class="form-group">
                    <select class="form-control" name="name">
                        <option value=0>--搜索业务员--</option>
                        <?php foreach ($staff as $key => $value) : ?>
                            <option value=<?php echo $value['job_number']; ?>
                                <?php if ($value['job_number'] == yii::$app->request->get('name')) {
                                    echo 'selected';
                                } ?>>
                                <?php echo $value['name']; ?>
                            </option>
                        <?php endforeach; ?>
                    </select>
                </div>
                <div class="form-group">
                    <input type="date" class="form-control" name="begin_date"
                           value="<?php echo yii::$app->request->get('begin_date'); ?>"/>
                </div>
                <div class="form-group">
                    <input type="date" class="form-control" name="end_date"
                           value="<?php echo yii::$app->request->get('end_date'); ?>"/>
                </div>
                <div class="form-group">
                    <input type="text" class="form-control" value="<?php echo yii::$app->request->get('num'); ?>"
                           name="num" placeholder="搜索客户编号"/>
                </div>
                <div class="form-group">
                    <input type="text" class="form-control" name="customer_name"
                           value="<?php echo yii::$app->request->get('customer_name'); ?>" placeholder="搜索客户名称"/>
                </div>
                <div class="form-group">
                    <input type="text" class="form-control" name="invoice_order"
                           value="<?php echo yii::$app->request->get('invoice_order'); ?>" placeholder="搜索invoice"/>
                </div>
                <div class="form-group">
                    <input type="text" class="form-control" name="product"
                           value="<?php echo yii::$app->request->get('product'); ?>" placeholder="搜索产品"/>
                </div>
                <button class="btn btn-success">搜索</button>
            </div>

        </form>
        <br/>
        <ul class="nav nav-tabs">
            <li role="presentation" class="active" onclick="show(0,this)"><a href="#">费用数据</a></li>
            <li role="presentation" onclick="show(1,this)"><a href="#">仓库未审核</a></li>
        </ul>
        <div id="tabs">
            <div>
                <table class="table table-borderd">
                    <thead>
                    <tr>
                        <th style="width:40px">id</th>
                        <th>日期</th>
                        <th>业务员</th>
                        <th>拆分项</th>
                        <th style="width:3rem">出入库</th>
                        <th>客户编号</th>
                        <th>客户名称</th>
                        <th>产品</th>
                        <th>产品数量</th>
                        <th>包装费</th>
                        <th>纸箱费</th>
                        <th>提付费</th>
                        <th>装卸费</th>
                        <th>费用</th>
                        <th>费用合计</th>
                        <th>备注</th>
                        <th>invocie</th>
                        <th>业务员</th>
                        <th>最后更新时间</th>
                        <th style="width:140px">操作</th>
                    </tr>
                    </thead>

                    <?php if ($list) { ?>
                        <style>.table-input {
                                margin: 0px;
                                padding: 0px;
                                width: 100%;
                                border: none;
                            }</style>
                        <?php foreach ($list as $k => $v) { ?>
                            <tr>
                                <td><?php echo $v['id']; ?></td>
                                <td><?php echo $v['date']; ?></td>
                                <td>
                                    <select class="table-input"
                                            onchange="update_by_column(<?php echo $v['id']; ?>,'name',this)">
                                        <option value=0>--请选择--</option>
                                        <?php foreach ($staff as $v2) : ?>
                                            <option <?php if ($v2['job_number'] == $v['name']) {
                                                echo 'selected';
                                            } ?> value="<?php echo $v2['job_number']; ?>"><?php echo $v2['name']; ?></option>
                                        <?php endforeach; ?>
                                    </select>
                                </td>
                                <td><?php echo $v['pid'] != $v['id'] ? '拆分项' . $v['pid'] : ''; ?></td>
                                <td><?php echo $v['type'] == 1 ? '入库' : '出库'; ?></td>
                                <td><input style="<?php echo $v['same'] ? '' : 'color:red'; ?>"
                                           onchange="update_by_column(<?php echo $v['id']; ?>,'num',this)" type="text"
                                           class="table-input" value="<?php echo $v['num']; ?>"/></td>
                                <td><input style="<?php echo $v['same'] ? '' : 'color:red'; ?>"
                                           onchange="update_by_column(<?php echo $v['id']; ?>,'customer_name',this)"
                                           type="text"
                                           class="table-input" value="<?php echo $v['customer_name']; ?>"/></td>
                                <td><input onchange="update_by_column(<?php echo $v['id']; ?>,'product',this)"
                                           type="text"
                                           class="table-input" value="<?php echo $v['product']; ?>"/></td>
                                <td><input onchange="update_by_column(<?php echo $v['id']; ?>,'product_number',this)"
                                           type="text" class="table-input" value="<?php echo $v['product_number']; ?>"/>
                                </td>
                                <td><input onchange="update_by_column(<?php echo $v['id']; ?>,'package',this)"
                                           type="text"
                                           class="table-input" value="<?php echo $v['package']; ?>"/></td>
                                <td><input onchange="update_by_column(<?php echo $v['id']; ?>,'carton',this)"
                                           type="text"
                                           class="table-input" value="<?php echo $v['carton']; ?>"/></td>
                                <td><input onchange="update_by_column(<?php echo $v['id']; ?>,'pay',this)" type="text"
                                           class="table-input" value="<?php echo $v['pay']; ?>"/></td>
                                <td><input onchange="update_by_column(<?php echo $v['id']; ?>,'fee',this)" type="text"
                                           class="table-input" value="<?php echo $v['fee']; ?>"/></td>
                                <td><?php echo $v['unloading']; ?></td>
                                <td><input style="<?php echo $v['moneySame'] ? '' : 'color:red' ?>"
                                           onchange="update_by_column(<?php echo $v['id']; ?>,'pay_all',this)"
                                           type="text"
                                           class="table-input" value="<?php echo $v['pay_all']; ?>"/></td>
                                <td><input onchange="update_by_column(<?php echo $v['id']; ?>,'remark',this)"
                                           type="text"
                                           class="table-input" value="<?php echo $v['remark']; ?>"/></td>
                                <td><input onchange="update_by_column(<?php echo $v['id']; ?>,'invoice_order',this)"
                                           type="text"
                                           class="table-input" value="<?php echo $v['invoice_order']; ?>"/></td>

                                <td>
                                    <?php foreach ($staff as $v2) : ?>
                                        <?php if ($v2['job_number'] == $v['last_modify']) {
                                            echo $v2['name'];
                                        } ?>
                                    <?php endforeach; ?>
                                </td>
                                <td><?php echo $v['last_modify_time'] ? date('Y-m-d H:i:s', $v['last_modify_time']) : ''; ?></td>
                                <td>
                                    <button class="layui-btn layui-btn-small layui-btn-danger"
                                            onclick="del_repo_fee(<?php echo $v['id']; ?>)"
                                    >删除
                                    </button>
                                    <button class="btn btn-success"
                                            onclick="lockRecord(<?php echo $v['id']; ?>,<?php echo $v['lock_status']; ?>)">
                                        <?php echo $v['lock_status'] == 1 ? '解锁' : "锁定"; ?>
                                    </button>
                                    <?php if ($v['pid'] == $v['id']): ?>
                                        <button class="btn btn-primary" onclick="split(<?php echo $v['id']; ?>)">拆分
                                        </button>
                                    <?php endif; ?>
                                </td>
                            </tr>
                        <?php } ?>
                    <?php } ?>
                </table>
                <div id="page" style="display:inline-block;"></div>
                <span>共<?php echo $this->params['page']['count']; ?>条记录</span>
            </div>
            <div style="display: none">
                <table class="table ">
                    <thead>
                    <tr>
                        <th>日期</th>
                        <th>出入库</th>
                        <th>业务员</th>
                        <th>产品名称</th>
                        <th>产品数量</th>
                        <th>包装费</th>
                        <th>纸箱费</th>
                        <th>提付费</th>
                        <th>运费</th>
                        <th>卸货费</th>
                        <th>审核状态</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php foreach ($verifyList as $v): ?>
                        <tr>
                            <td><?php echo $v['date']; ?></td>
                            <td><?php echo $v['type'] == 1 ? '入库' : '出库'; ?></td>
                            <td>
                                <?php foreach ($staff as $v2): ?>
                                    <?php if ($v2['job_number'] == $v['staff']): ?>
                                        <?php echo $v2['name']; ?>
                                    <?php endif; ?>
                                <?php endforeach; ?>
                            </td>
                            <td><?php echo $v['product']; ?></td>
                            <td><?php echo $v['product_number']; ?></td>
                            <td><?php echo $v['package']; ?></td>
                            <td><?php echo $v['carton']; ?></td>
                            <td><?php echo $v['pay']; ?></td>
                            <td><?php echo $v['fee']; ?></td>
                            <td><?php echo $v['unloading']; ?></td>
                            <td>
                                <?php if ($v['verify'] == 2): ?>
                                    <span class="label label-success">审核成功</span>
                                <?php else: ?>
                                    <span class="label label-info">未审核</span>
                                <?php endif; ?>
                            </td>
                            <td>
                                <button onclick="addRecord(<?php echo $v['id']; ?>)" class="btn btn-success">审核成功
                                </button>
                            </td>
                        </tr>
                    <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
        </div>
        <script>
            function addRecord(v) {
                layer.confirm('确认审核', function () {
                    $.post('/api/repo/new-record', {id: v}, function (res) {
                        if (res.code == 1) {
                            layer.alert(res.msg);
                        } else {
                            layer.alert(res.msg);
                        }
                    }, 'json');
                })
            }

            function show(v, e) {
                $(e).addClass('active');
                $(e).siblings().removeClass('active');
                $("#tabs").children().hide();
                $($("#tabs").children()[v]).show();
            }
        </script>
        <script>
            layui.laypage({
                cont: 'page'
                , pages: <?php echo $this->params['page']['page'];?>
                , curr:<?php echo $this->params['page']['curr'];?>
                , skin: '#5FB878'
                , skip: true
                , jump: function (obj, first) {
                    if (!first) {
                        if (window.location.search) {
                            window.location.href = "<?php echo $this->params['page']['base_url'];?>&p=" + obj.curr;
                        }
                        else {
                            window.location.href = "<?php echo $this->params['page']['base_url'];?>?p=" + obj.curr;
                        }

                    }
                }
            });

            function update_by_column(id, column, e) {
                if (layer.confirm('确认修改', {}, function () {
                        var url = "<?php echo Url::to(['table/repo_edit_by_column']);?>"
                        $.post(url, {id: id, column: column, v: e.value}, function (res) {
                            if (res.code == 1) {
                                layer.confirm(res.msg, {}, function () {
                                    window.location.reload();
                                })
                            }
                            else {
                                layer.alert(res.msg);
                            }
                        }, 'json')
                    })) ;
            }

            function del_repo_fee(v) {
                var url = "<?php echo Url::to(['table/del_repo_by_id']);?>";
                if (layer.confirm('确认删除', {}, function () {
                        $.post(url, {id: v}, function (res) {
                            if (res.code == 1) {
                                layer.confirm(res.msg, {}, function () {
                                    window.location.reload();
                                })
                            }
                            else {
                                layer.alert(res.msg);
                            }
                        }, 'json')
                    })) ;
            }

            function lockRecord(id, lock_status) {
                var content = (lock_status == 1) ? '确认解锁' : '确认锁定';
                var data = {};
                data.id = id;
                data.param = 'lock_status';
                lock_status = lock_status == 1 ? 2 : 1;
                data.value = lock_status;
                layer.confirm(content, {}, function () {
                    $.post('/table/lock-repo', data, function (res) {
                        layer.alert(res.msg);
                        setTimeout(function () {
                            window.location.reload();
                        }, 1000)
                    }, 'json')
                })
            }

            function add() {
                zeroModal.show({url: '/api/add_repo'});
            }

            function split(id) {
                layer.confirm('确认拆分', {}, function () {
                    $.post('/table/repo-split', {id: id}, function (res) {
                        layer.alert(res.msg);
                        if (res.code == 1) {
                            setTimeout(function () {
                                window.lcoation.reload();
                            }, 1000)
                        }
                    }, 'json')
                })
            }
        </script>
    </div>
<?php echo $this->render('/public/footer'); ?>